package blog.com.mw.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import blog.com.mw.base.ResultData;
import blog.com.mw.pojo.vo.LabelTypeVO;
import blog.com.mw.pojo.vo.LabelVO;
import blog.com.mw.service.LabelService;

@RestController
@RequestMapping("/label")
public class LabelController {

	@Autowired
	private LabelService service;
	
	@RequestMapping(value = "/label", method = RequestMethod.GET)
	public ResultData getLabelById(@RequestParam("id") int id) {
		ResultData rs = null;
		rs = service.getLabelById(id);
		return rs;
	}
	
	@RequestMapping(value = "/getLabelByContent", method = RequestMethod.GET)
	public ResultData getLabelByContent(@RequestParam("content") String content) {
		ResultData rs = null;
		rs = service.getLabelByContent(content);
		return rs;
	}
	
	@RequestMapping(value = "/getLabelByArticleId", method = RequestMethod.GET)
	public ResultData getLabelByArticleId(@RequestParam("articleId") int articleId) {
		ResultData rs = null;
		rs = service.getLabelByArticleId(articleId);
		return rs;
	}
	
	@RequestMapping(value = "/label", method = RequestMethod.POST)
	public ResultData addLabel(@RequestBody LabelVO vo) {
		ResultData rs = null;
		rs = service.addLabel(vo);
		return rs;
	}
	
	@RequestMapping(value = "/label", method = RequestMethod.DELETE)
	public ResultData delLabel(@RequestParam("id") int id) {
		ResultData rs = null;
		rs = service.delLabel(id);
		return rs;
	}
	
	@RequestMapping(value = "/labelTypeList",method = RequestMethod.GET)
	public ResultData getAllLabelType(@RequestParam("page") int pageNum,@RequestParam("limit") int pageSize
			,@RequestParam(value="keyword", required=false)String keyword) {
		ResultData rs = null ;
		rs = service.getAllLabelType(pageNum,pageSize,keyword);
		return rs;
	}
	
	@RequestMapping(value = "/labelType",method = RequestMethod.GET)
	public ResultData getLabelTypeById(@RequestParam("id") int id) {
		ResultData rs = null ;
		rs = service.getLabelTypeById(id);
		return rs;
	}
	
	@RequestMapping(value = "/getLabelTypeByContent", method = RequestMethod.GET)
	public ResultData getLabelTypeByContent(@RequestParam("content") String content) {
		ResultData rs = null;
		rs = service.getLabelTypeByContent(content);
		return rs;
	}
	
	@RequestMapping(value = "/labelType",method = RequestMethod.POST)
	public ResultData addLabelType(@RequestBody LabelTypeVO vo) {
		ResultData rs = null ;
		rs = service.addLabelType(vo);
		return rs;
	}
	
	@RequestMapping(value = "/labelType",method = RequestMethod.PUT)
	public ResultData updateLabelType(@RequestBody LabelTypeVO vo) {
		ResultData rs = null ;
		rs = service.updateLabelType(vo);
		return rs;
	}
	
	@RequestMapping(value = "/labelType/{id}",method = RequestMethod.DELETE)
	public ResultData delLabelType(@PathVariable("id") int id) {
		ResultData rs = null ;
		List<Integer> ids = new ArrayList<>();
		ids.add(id);
		rs = service.delLabelType(ids);
		return rs;
	}
	
	@RequestMapping(value = "/labelType",method = RequestMethod.DELETE)
	public ResultData delLabelTypeByIds(@RequestBody List<Integer> ids) {
		ResultData rs = null ;
		rs = service.delLabelType(ids);
		return rs;
	}
}
